<?php
namespace App\Libraries\Tools;


use App\Models\Product\CityDiscount;
use App\Models\User\User;

class MLM
{
    /**
     * 根据城市获取VIP优惠
     * @param $user_id
     * @return int
     */
    static public function getVIPDiscount($user_id){
        $data = \App\Models\MLM\MLM::where('user_id', $user_id)->first();
        if(empty($data) || empty($data->l_agent_id)){
            return 1;
        }
        $agent = User::where('user_id', $data->l_agent_id)->where('status', 1)->first();
        if(empty($agent) || empty($agent->agent_city_id)){
            return 1;
        }
        $discount = CityDiscount::where('city_id', $agent->agent_city_id)->first();
        if(empty($discount) || $discount->discount == '0.00'){
            return 1;
        }
        return $discount->discount;
    }
}